//
//  LFMeViewController.m
//  LoveFreshBee
//
//  Created by 王忠迪 on 10/15/16.
//  Copyright © 2016 王忠迪. All rights reserved.
//

#import "LFMeViewController.h"
#import "ZHMineHeadView.h"
#import "ZHTableHeadView.h"
#import "ZHMineTableView.h"
#import "ZHMyAddressViewController.h"
#import "ZHMyShopViewController.h"
#import "ZHMyHelpViewController.h"
#import "ZHMySuggestViewController.h"

@interface LFMeViewController ()<ZHMineHeadViewDelegate,UITableViewDelegate>

@property(weak,nonatomic)ZHMineHeadView *headView;

@property(weak,nonatomic)ZHTableHeadView *tableHeadView;

@property(weak,nonatomic)ZHMineTableView *tableView;

@end

@implementation LFMeViewController

- (void)loadView {
    [super loadView];
    //在控制器的加载View的时候隐藏导航条
    self.navigationController.navigationBar.hidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor whiteColor];
    
    [self setupUI];
}

- (void)setupUI {
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    ZHMineHeadView *headBarView = [[ZHMineHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH*0.23)];
    
    headBarView.delegate = self;
    
    [self.view addSubview:headBarView];
    
    [self setupTableView];
}

- (void)setupTableView {
    
    ZHMineTableView *tableView = [[ZHMineTableView alloc]initWithFrame:CGRectMake(0, kScreenH*0.23, kScreenW, kScreenH*0.77) style:UITableViewStyleGrouped];
    _tableView = tableView;
    //设置代理
    tableView.delegate = self;
    
    //设置tableHeaderView
    ZHTableHeadView *tableHeadView = [[ZHTableHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH*0.11)];
    
    _tableHeadView = tableHeadView;
    //把自定义的tableHeaderView 添加到自定义的tableView 上去
    tableView.tableHeaderView = tableHeadView;
    
    [self.view addSubview:tableView];
    
}


#pragma mark - UITableViewDelegate
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 11;
}

//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

//tableViewCell 被点击的代理方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (0 == indexPath.section) {
        if (0 == indexPath.row) {
            ZHMyAddressViewController *addressVc = [[ZHMyAddressViewController alloc]init];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            addressVc.navItem.title = cell.textLabel.text;
            [self.navigationController pushViewController:addressVc animated:YES];
        } else {
            ZHMyShopViewController *myShopVc = [[ZHMyShopViewController alloc]init];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            myShopVc.navItem.title = cell.textLabel.text;
            [self.navigationController pushViewController:myShopVc animated:YES];
        }
    } else if (1 == indexPath.section) {
        //弹窗
        [self popupAlertView];
        
    } else if (2 == indexPath.section) {
        if (0 == indexPath.row) {
            
            ZHMyHelpViewController *help = [[ZHMyHelpViewController alloc]init];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            help.navItem.title = cell.textLabel.text;
            [self.navigationController pushViewController:help animated:YES];
            
        } else {
            
            ZHMySuggestViewController *suggest = [[ZHMySuggestViewController alloc]init];
            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            suggest.navItem.title = cell.textLabel.text;
            [self.navigationController pushViewController:suggest animated:YES];
        }
    }
    
}


//设置页面
- (void)loginSettingViewController:(ZHBaseViewController *)settingVC {
    
    //这里不需要让导航条显示，因为要让自定义导航条显示
    
    //push
    [self.navigationController pushViewController:settingVC animated:YES];
}


//弹窗
- (void)popupAlertView {
    //先跳出弹窗,然后再跳转页面;
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"分享到" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction* action1 = [UIAlertAction actionWithTitle:@"微信好友" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    
    [alert addAction:action1];
    
    
    
    UIAlertAction* action2 = [UIAlertAction actionWithTitle:@"微信朋友圈" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    
    [alert addAction:action2];
    
    
    
    UIAlertAction* action3 = [UIAlertAction actionWithTitle:@"新浪微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    
    [alert addAction:action3];
    
    
    UIAlertAction* action4 = [UIAlertAction actionWithTitle:@"QQ空间" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
    }];
    
    [alert addAction:action4];
    
    UIAlertAction* action5 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alert addAction:action5];
    
    
    
    [self presentViewController:alert animated:YES completion:^{
        
    }];
    
}



@end
